<template>
  <div>
    <div class="ccui-navigation">
      <el-button
        size="mini"
        type="primary-icon-medium"
        icon="icon-ccui-return"
        @click="handleBack"
        >返回</el-button
      >
      <div class="ccui-navigation-divider" />
      <!-- 面包屑 -->
      <el-breadcrumb
        class="ccui-navigation-crumbs-container"
        separator-class="el-icon-arrow-right"
      >
        <el-breadcrumb-item
          :to="{ path: $store.getters.getBreadcrumb('level1').path }"
          >{{ $store.getters.getBreadcrumb("level1").name }}</el-breadcrumb-item
        >
        <el-breadcrumb-item :to="{ path: '/checkmanagement' }"
          >验收管理</el-breadcrumb-item
        >
        <el-breadcrumb-item
          :to="{ path: '/checkManagement/acceptanceAccount/list' }"
          >验收台账</el-breadcrumb-item
        >
        <!-- <el-breadcrumb-item
          :to="{ path: '/checkManagement/acceptanceAccount/list' }"
          >到货验收</el-breadcrumb-item
        > -->
        <el-breadcrumb-item>
          <span>查看</span>
          <span class="ccui-curr-crumb ccui-ml-10">
            {{
              acceptDetailData.acceptanceCertBO &&
              acceptDetailData.acceptanceCertBO.acceptanceName
                ? acceptDetailData.acceptanceCertBO.acceptanceName
                : ""
            }}
          </span>
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div v-if="isTrue" class="ccui-app-container-detail">
      <div class="ccui-app-container-detail-body">
        <el-tabs v-model="activeName" class="el-tabs__customize">
          <el-tab-pane label="基本信息" name="first">
            <!-- 按发货单 -->
            <detailBaseInfo
              v-if="acceptDetailData.acceptanceCertBO.acceptanceTypeCode == '1'"
              ref="formBIU"
              labelWidth="160px"
              :formList="daBasicInfoList"
              :detail="acceptDetailData.acceptanceCertBO"
            />
            <!-- 按订单验收 -->
            <detailBaseInfo
              v-if="acceptDetailData.acceptanceCertBO.acceptanceTypeCode == '2'"
              ref="formBIU"
              labelWidth="160px"
              :formList="orderBasicInfoList"
              :detail="acceptDetailData.acceptanceCertBO"
            />
            <!-- 按合同验收 -->
            <detailBaseInfo
              v-if="acceptDetailData.acceptanceCertBO.acceptanceTypeCode == '3'"
              ref="formBIU"
              labelWidth="160px"
              :formList="contractBasicInfoList"
              :detail="acceptDetailData.acceptanceCertBO"
            />
          </el-tab-pane>
          <el-tab-pane label="采购清单" name="second">
            <!-- 按发货单 -->
            <oneLineTable
              v-if="acceptDetailData.acceptanceCertBO.acceptanceTypeCode == '1'"
              showSummary
              :summaryArr="summaryArr"
              :tableTheadOptions="daHeaderList"
              :oneLineTableData="acceptDetailData.acceptanceBillBOList"
            />
            <!-- 按订单验收 -->
            <oneLineTable
              v-if="acceptDetailData.acceptanceCertBO.acceptanceTypeCode == '2'"
              showSummary
              :summaryArr="summaryArr"
              :tableTheadOptions="orderHeaderList"
              :oneLineTableData="acceptDetailData.acceptanceBillBOList"
            />
            <!-- 按合同验收 -->
            <oneLineTable
              v-if="acceptDetailData.acceptanceCertBO.acceptanceTypeCode == '3'"
              showSummary
              :summaryArr="summaryArr1"
              :tableTheadOptions="contractHeaderList"
              :oneLineTableData="acceptDetailData.acceptanceBillBOList"
            />
          </el-tab-pane>
          <el-tab-pane label="附件信息" name="third">
            <uploadInfo isTab showType state="detail" v-model="detailData" />
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>

    <!--  底部导航栏及签名导出  -->
    <bottomGuide
      v-if="isTrue"
      busiType="102"
      approvalStatus="approvaled"
      exportMethod="get"
      methodGetPageType="exportAcceptanceOrder"
      :curPageId="$route.params.id"
      :businessCode="businessCode"
      @handleBack="handleBack"
    />
  </div>
</template>

<script>
import { getSessionItem, formatNumber } from "@/basa/utils";
import publicComponent from "@/basa/components/public";
import { getAcceptanceCert } from "../api/item-list";
import Mixins from "../mixins";
export default {
  name: "listquery-new-item",
  mixins: [Mixins],
  components: {
    detailBaseInfo: publicComponent.detailBaseInfo,
    oneLineTable: publicComponent.oneLineTable,
    uploadInfo: publicComponent.uploadInfo,
    bottomGuide: publicComponent.bottomGuide
  },
  data() {
    return {
      exportLoading: null,
      businessCode: "",
      activeName: "first",
      readonlyInput: true,
      title: "新增信息",
      submitFlag: false,
      // 附件
      id: "",
      mcConcMeasureBasic: {},
      mcConcMeasureSummary: [],
      mcConcMeasureDetail: [],
      mcConcMeasureAdjust: [],
      mcConcMeasureClaim: [],
      mcConcMeasurePayments: [],
      currAmountTax: "",
      // 按发货单列表
      daBasicInfoList: [
        {
          label: "填报单位",
          titleContent: "reportInOrgName"
        },
        {
          label: "供应商",
          titleContent: "supplier"
        },
        {
          label: "验收单编号",
          titleContent: "acceptanceNumber"
        },
        {
          label: "验收单名称",
          titleContent: "acceptanceName"
        },
        {
          label: "发货单编号",
          titleContent: "invoiceNumber"
        },
        {
          label: "发货单名称",
          titleContent: "invoiceName"
        },
        {
          label: "订单编号",
          titleContent: "orderNumber"
        },
        {
          label: "司机姓名",
          titleContent: "driverName"
        },
        {
          label: "司机手机号",
          titleContent: "driverPhone"
        },
        {
          label: "车牌号",
          titleContent: "plateNumber"
        },
        // {
        //   label: "到货地点",
        //   titleContent: "arrivalPlace"
        // },
        // {
        //   label: "车牌号",
        //   titleContent: "plateNumber"
        // },
        // {
        //   label: "司机姓名",
        //   titleContent: "driverName"
        // },
        // {
        //   label: "司机手机号",
        //   titleContent: "driverPhone"
        // },
        // {
        //   label: "供应商联系电话",
        //   titleContent: "supplierPhone"
        // },
        {
          label: "编制人",
          titleContent: "compilePeople"
        },
        {
          label: "编制日期",
          titleContent: "compileDate"
        },
        {
          label: "验收人",
          titleContent: "acceptor"
        },
        {
          label: "验收人联系电话",
          titleContent: "acceptancePhone"
        },
        {
          label: "供应商联系电话",
          titleContent: "supplierPhone"
        },
        {
          label: "备注",
          titleContent: "remake",
          span: 18,
          title: true
        },
        {
          label: "品牌星级",
          titleContent: "brandStar",
          span: 18,
          isRate: true
        },
        {
          label: "品牌评价说明",
          titleContent: "brandState",
          span: 18,
          title: true
        },
        {
          label: "外观质量星级",
          titleContent: "appearanceStar",
          span: 18,
          isRate: true
        },
        {
          label: "外观质量说明",
          titleContent: "appearanceState",
          span: 18,
          title: true
        },
        {
          label: "数量星级",
          titleContent: "numberStar",
          span: 18,
          isRate: true
        },
        {
          label: "数量评价说明",
          titleContent: "numberState",
          span: 18,
          title: true
        },
        {
          label: "物流评价星级",
          titleContent: "logisticsEvaluationStar",
          span: 18,
          isRate: true
        },
        {
          label: "物流评价说明",
          titleContent: "logisticsEvaluationState",
          span: 18,
          title: true
        },
        {
          label: "物流现场配合度星级",
          titleContent: "logisticsCoordinationStar",
          span: 18,
          isRate: true
        },
        {
          label: "物流现场配合度说明",
          titleContent: "logisticsCoordinationState",
          span: 18,
          title: true
        }
      ],
      // 按订单列表
      orderBasicInfoList: [
        {
          label: "填报单位",
          titleContent: "reportInOrgName"
        },
        {
          label: "供应商",
          titleContent: "supplier"
        },
        {
          label: "验收单编号",
          titleContent: "acceptanceNumber"
        },
        {
          label: "验收单名称",
          titleContent: "acceptanceName"
        },
        {
          label: "订单编号",
          titleContent: "orderNumber"
        },
        {
          label: "订单名称",
          titleContent: "orderName"
        },
        // {
        //   label: "司机姓名",
        //   titleContent: "driverName"
        // },
        {
          label: "车牌号",
          titleContent: "plateNumber"
        },
        {
          label: "司机姓名",
          titleContent: "driverName"
        },
        {
          label: "司机手机号",
          titleContent: "driverPhone"
        },
        // {
        //   label: "到货地点",
        //   titleContent: "arrivalPlace"
        // },
        {
          label: "供应商联系电话",
          titleContent: "supplierPhone"
        },
        {
          label: "验收人联系电话",
          titleContent: "acceptancePhone"
        },
        {
          label: "验收人",
          titleContent: "acceptor"
        },
        {
          label: "编制人",
          titleContent: "compilePeople"
        },

        {
          label: "编制日期",
          titleContent: "compileDate"
        },
        {
          label: "备注",
          titleContent: "remake",
          span: 18,
          title: true
        },
        {
          label: "品牌星级",
          titleContent: "brandStar",
          span: 18,
          isRate: true
        },
        {
          label: "品牌评价说明",
          titleContent: "brandState",
          span: 18,
          title: true
        },
        {
          label: "外观质量星级",
          titleContent: "appearanceStar",
          span: 18,
          isRate: true
        },
        {
          label: "外观质量说明",
          titleContent: "appearanceState",
          span: 18,
          title: true
        },
        {
          label: "数量星级",
          titleContent: "numberStar",
          span: 18,
          isRate: true
        },
        {
          label: "数量评价说明",
          titleContent: "numberState",
          span: 18,
          title: true
        },
        {
          label: "物流评价星级",
          titleContent: "logisticsEvaluationStar",
          span: 18,
          isRate: true
        },
        {
          label: "物流评价说明",
          titleContent: "logisticsEvaluationState",
          span: 18,
          title: true
        },
        {
          label: "物流现场配合度星级",
          titleContent: "logisticsCoordinationStar",
          span: 18,
          isRate: true
        },
        {
          label: "物流现场配合度说明",
          titleContent: "logisticsCoordinationState",
          span: 18,
          title: true
        }
      ],
      // 按发货单采购清单表格
      daHeaderList: [
        {
          label: "设备物资编码",
          prop: "materialCode",
          width: "110",
          fixed: true
        },
        {
          label: "设备物资名称",
          prop: "materialName",
          width: "300",
          fixed: true
        },
        {
          label: "设备物资说明",
          prop: "materialState",
          width: "130"
        },
        {
          label: "分类名称",
          prop: "categoryName",
          width: "130"
        },
        {
          label: "计量单位",
          prop: "measureUnit",
          width: "90"
        },
        {
          label: "验收日期",
          prop: "acceptanceDate",
          width: "100"
        },
        {
          label: "验收地点",
          prop: "daohuo",
          width: "200"
        },
        {
          label: "发货单累计验收数量",
          prop: "invoiceTotalAcceptanceNumber",
          width: "150"
        },
        // {
        //   label: "合同数量",
        //   prop: "contractNumber",
        //   width: "100"
        // },
        // {
        //   label: "合同累计验收数量",
        //   prop: "concTotalAcceptanceNumber"
        // },
        // {
        //   label: "订单数量",
        //   prop: "orderNumber"
        // },
        {
          label: "发货单数量",
          prop: "deliveryCurrentNumber",
          width: "130"
        },
        // {
        //   label: "验收数量",
        //   prop: "currentTotalAcceptanceNumber"
        // },
        // {
        //   label: "本次发货数量",
        //   prop: "deliveryCurrentNumber"
        // },
        {
          label: "本次验收数量",
          prop: "acceptanceCurrentNumber",
          width: "130"
        },
        {
          label: "生产厂家/品牌",
          prop: "manufacturerBrand",
          width: "130"
        }
      ],
      // 按发货 按订单 合计
      summaryArr: [
        "invoiceTotalAcceptanceNumber",
        "contractNumber",
        "orderNumber",
        "orderTotalAcceptanceNumber",
        "acceptanceNumber",
        "deliveryCurrentNumber",
        "acceptanceCurrentNumber"
      ],
      // 按订单采购清单表格
      orderHeaderList: [
        {
          label: "设备物资编码",
          prop: "materialCode",
          width: "110",
          fixed: true
        },
        {
          label: "设备物资名称",
          prop: "materialName",
          width: "300",
          fixed: true
        },
        {
          label: "设备物资说明",
          prop: "materialState",
          width: "130"
        },
        {
          label: "分类名称",
          prop: "categoryName",
          width: "130"
        },
        {
          label: "计量单位",
          prop: "measureUnit",
          width: "90"
        },
        {
          label: "验收日期",
          prop: "acceptanceDate",
          width: "100"
        },
        {
          label: "验收地点",
          prop: "daohuo",
          width: "200"
        },
        {
          label: "订单累计验收数量",
          prop: "orderTotalAcceptanceNumber",
          width: "130"
        },
        {
          label: "订单数量",
          prop: "orderNumber",
          width: "100"
        },

        // {
        //   label: "发货数量",
        //   prop: "deliveryCurrentNumber"
        // },
        // {
        //   label: "验收数量",
        //   prop: "currentTotalAcceptanceNumber"
        // },
        // {
        //   label: "本次发货数量",
        //   prop: "deliveryCurrentNumber",
        //   width: "130"
        // },
        {
          label: "本次验收数量",
          prop: "acceptanceCurrentNumber",
          width: "130"
        },
        {
          label: "生产厂家/品牌",
          prop: "manufacturerBrand",
          width: "130"
        }
      ],
      // 按合同采购清单表格
      contractHeaderList: [
        {
          label: "设备物资编码",
          prop: "materialCode",
          width: "110",
          fixed: true
        },
        {
          label: "设备物资名称",
          prop: "materialName",
          width: "300",
          fixed: true
        },
        {
          label: "设备物资说明",
          prop: "materialState",
          width: "130"
        },
        {
          label: "分类名称",
          prop: "categoryName",
          width: "130"
        },
        {
          label: "计量单位",
          prop: "measureUnit",
          width: "90"
        },
        {
          label: "验收日期",
          prop: "acceptanceDate",
          width: "100"
        },
        {
          label: "验收地点",
          prop: "daohuo",
          width: "200"
        },
        {
          label: "合同累计验收数量",
          prop: "concTotalAcceptanceNumber",
          width: "130"
        },
        {
          label: "合同数量",
          prop: "contractNumber",
          width: "100"
        },

        // {
        //   label: "订单数量",
        //   prop: "orderNumber"
        // },
        // {
        //   label: "发货数量",
        //   prop: "deliveryCurrentNumber"
        // },
        // {
        //   label: "验收数量",
        //   prop: "currentTotalAcceptanceNumber"
        // },
        // {
        //   label: "本次发货数量",
        //   prop: "deliveryCurrentNumber"
        // },
        {
          label: "本次验收数量",
          prop: "acceptanceCurrentNumber",
          width: "130"
        },
        {
          label: "生产厂家/品牌",
          prop: "manufacturerBrand",
          width: "130"
        }
      ],
      // 按合同 合计
      summaryArr1: [
        "contractNumber",
        "acceptanceNumber",
        "acceptanceCurrentNumber",
        "concTotalAcceptanceNumber"
      ],
      //按合同验收
      contractBasicInfoList: [
        {
          label: "填报单位",
          titleContent: "reportInOrgName"
        },
        {
          label: "供应商",
          titleContent: "supplier"
        },
        {
          label: "验收单编号",
          titleContent: "acceptanceNumber"
        },
        {
          label: "验收单名称",
          titleContent: "acceptanceName"
        },
        {
          label: "合同编号",
          titleContent: "contractNumber"
        },
        {
          label: "合同名称",
          titleContent: "contractName"
        },
        {
          label: "供应商联系电话",
          titleContent: "supplierPhone"
        },
        {
          label: "车牌号",
          titleContent: "plateNumber"
        },
        {
          label: "司机姓名",
          titleContent: "driverName"
        },
        {
          label: "司机手机号",
          titleContent: "driverPhone"
        },
        {
          label: "验收人",
          titleContent: "acceptor"
        },
        {
          label: "验收人联系电话",
          titleContent: "acceptancePhone"
        },
        {
          label: "编制日期",
          titleContent: "compileDate"
        },
        {
          label: "编制人",
          titleContent: "compilePeople"
        },
        {
          label: "备注",
          titleContent: "remake",
          span: 18,
          title: true
        },
        {
          label: "品牌星级",
          titleContent: "brandStar",
          span: 18,
          isRate: true
        },
        {
          label: "品牌评价说明",
          titleContent: "brandState",
          span: 18,
          title: true
        },
        {
          label: "外观质量星级",
          titleContent: "appearanceStar",
          span: 18,
          isRate: true
        },
        {
          label: "外观质量说明",
          titleContent: "appearanceState",
          span: 18,
          title: true
        },
        {
          label: "数量星级",
          titleContent: "numberStar",
          span: 18,
          isRate: true
        },
        {
          label: "数量评价说明",
          titleContent: "numberState",
          span: 18,
          title: true
        },
        {
          label: "物流评价星级",
          titleContent: "logisticsEvaluationStar",
          span: 18,
          isRate: true
        },
        {
          label: "物流评价说明",
          titleContent: "logisticsEvaluationState",
          span: 18,
          title: true
        },
        {
          label: "物流现场配合度星级",
          titleContent: "logisticsCoordinationStar",
          span: 18,
          isRate: true
        },
        {
          label: "物流现场配合度说明",
          titleContent: "logisticsCoordinationState",
          span: 18,
          title: true
        }
      ],
      isTrue: false,
      // 附件返回数据
      detailData: [{ fileType: "现场验收单" }],
      // 详情数据
      acceptDetailData: {},
      breadcrumbLastItem: ""
    };
  },
  created() {
    this.getData();
  },
  activated() {
    this.getData();
  },
  deactivated() {
    this.isTrue = false;
  },
  methods: {
    // 返回
    handleBack() {
      this.$router.push("/checkManagement/acceptanceAccount/list");
      this.nextIsTrue();
    },
    // 数据请求
    getData() {
      const { id } = this.$route.params;
      getAcceptanceCert({ id }).then(res => {
        this.setDate(res.data.data);
        this.businessCode = res.data.data.acceptanceCertBO.acceptanceNumber;
        res.data.data.acceptanceBillBOList =
          res.data.data.acceptanceBillBOList.map(item => ({
            ...item,
            invoiceTotalAcceptanceNumber: formatNumber(
              item.invoiceTotalAcceptanceNumber,
              3
            ),
            contractNumber: formatNumber(item.contractNumber, 3),
            deliveryCurrentNumber: formatNumber(item.deliveryCurrentNumber, 3),
            acceptanceCurrentNumber: formatNumber(
              item.acceptanceCurrentNumber,
              3
            ),
            orderTotalAcceptanceNumber: formatNumber(
              item.orderTotalAcceptanceNumber,
              3
            ),
            concTotalAcceptanceNumber: formatNumber(
              item.concTotalAcceptanceNumber,
              3
            ),
            daohuo:
              item.areaName +
              item.provinceName +
              item.cityName +
              item.countyName +
              item.acceptancePlace
          }));
        this.acceptDetailData = res.data.data;
        let arr = [
          ...res.data.data.otherFiles.map(item => ({
            ...item,
            fileType: "其他"
          })),
          ...res.data.data.sceneFiles.map(item => ({
            ...item,
            fileType: "现场验收单"
          }))
        ];

        arr.sort((a, b) => a.sn - b.sn);

        this.detailData = arr;
        this.setDate(this.detailData);

        // console.log(
        //   this.acceptDetailData.acceptanceCertBO.acceptanceTypeCode,
        //   "验收单类型编码"
        // );
        // 按发货单验收
        // if (this.acceptDetailData.acceptanceCertBO.acceptanceTypeCode === 1) {
        //   this.daHeaderList.splice(8, 0, {
        //     label: "本次发货数量",
        //     prop: "deliveryCurrentNumber"
        //   });
        // }
        // 按订单验收
        // if (this.acceptDetailData.acceptanceCertBO.acceptanceTypeCode === 2) {
        //   this.daHeaderList.splice(7, 1);
        //   this.daHeaderList.splice(8, 0, {
        //     label: "本次验收数量",
        //     prop: "acceptanceCurrentNumber"
        //   });
        // }
        // // 按合同验收
        // if (this.acceptDetailData.acceptanceCertBO.acceptanceTypeCode === 3) {
        //   this.daHeaderList.splice(7, 1);
        //   this.daHeaderList.splice(6, 0, {
        //     label: "订单数量",
        //     prop: "orderNumber"
        //   });
        // }
        // 这一行写到接口请求最后
        this.isTrue = true;
      });
    },
    // 时间处理
    setDate(item) {
      // 循环数组
      if (Array.isArray(item)) {
        item.map(Item => {
          this.setDate(Item);
        });
      } else {
        // 循环对象
        for (var key in item) {
          if (item[key]) {
            if (key.indexOf("Date") != -1) {
              item[key] = item[key].split(" ")[0];
            }
            // 判断类型为 对象类型 循环
            if (item[key] instanceof Object) {
              this.setDate(item[key]);
            }
          }
        }
      }
    },
    //  必须得在保存时 返回 放到最后引用
    nextIsTrue() {
      this.$nextTick(() => {
        this.isTrue = false;
      });
    }
  },
  computed: {
    // 获取面包屑
    getBreadcrumb() {
      return getSessionItem("breadcrumb");
    }
  }
};
</script>
<style lang="scss" scoped>
/deep/ .el-table__fixed-header-wrapper {
  th {
    pointer-events: auto;
  }
}

/deep/ .el-table__fixed,
/deep/.el-table__fixed-right {
  pointer-events: none;
  td {
    pointer-events: auto;
  }
}
</style>
